package com.shelpe.services.sinbad.entity.mongo;

import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.shelpe.services.sinbad.service.simbaproxy.RankClient;

import lombok.Data;

@Data
@Document(collection = "keyword_realtime_rank_sync_logs")
public class KeywordRealtimeRankSyncLog {
	@Id
	private String id;
	private KeywordRankItem item;
	@Indexed
	private long keywordID;
	@Indexed
	private long adgroupID;
	@Indexed
	private Date date;
	private int minute;

	public void from(long adgroupID, long keywordID, Date createTime, int minute) {
		this.setAdgroupID(adgroupID);
		this.setKeywordID(keywordID);
		this.setDate(createTime);
		this.setMinute(minute);
		this.setupID(adgroupID, createTime);
	}

	public void setupID(long adgroupID, Date time) {
		this.id = keywordID + "-" + DateFormatUtils.format(time, "yyyyMMddHHmm");
	}

	@Data
	public static class KeywordRankItem {
		private String word;
		private long keywordID;
		private RankClient.KeywordRealtimeRankItem rank;
	}
}
